<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入依赖包 -->
    <script src="./js/vue.js"></script>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        ul{
            list-style: none;
            width: 400px;
        }
        li{
            height: 20px;
            width: 100%;
            text-align: center;
            margin: 10px 0px;
        }
        .cur{
            background: yellowgreen;   
        }
    </style>
</head>
<body>
     <!-- 模板（容器） -->
     <div class="app">
          <!-- 无序列表展示 -->
          <ul>
              <li v-for=" (item,index) in category " :key="item.id" @mouseenter="handler(index)" :class="{cur:currentIndex==index}">
                   {{item.name}}---{{index}}
              </li>
          </ul>
     </div>
</body>
</html>
<script>
    //创建VM实例
    let VM = new Vue({
        //element全称:第一种字符串（选择器）
        //第二种：书写真实的DOM节点-document.querySelector('.app')
        el:'.app',
        data:{
            //菜单的数据的来源
            category:[
                {id:1,name:"貂蝉"},
                {id:2,name:"吕布"},
                {id:3,name:"刘备"},
                {id:4,name:"曹操"},
                {id:5,name:"鲁班"},
                {id:6,name:"鲁班大师"},
                {id:7,name:"后裔"},
                {id:8,name:"诸葛亮"},
            ],
            //响应式数据currentIndex,代表鼠标已进入的那个元素的索引值
            currentIndex:0
        },
        methods: {
            //鼠标进入相关的回调函数
            handler(index){
                this.currentIndex = index;
            }
        },
    })
</script>